package com.topideal.supplychain.hades.master.mapper;

import com.topideal.supplychain.hades.master.model.Component;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 模块sql
 *
 * @author xuxiaoyan
 * @date 2018-09-19 15:16
 */
@Mapper
public interface ComponentMapper {

    /**
     * 根据模块id或模块名搜索模块
     *
     * @param query
     * @return
     */
    @Select("<script> " +
            "select c.ID as id, c.cname as cName, p.pname as pName "
            + "from component c "
            + "inner join project p on p.ID = c.PROJECT"
            + "<where>"
            + " <if test=\"query != null and query != '' \"> "
            + "and ( c.ID like concat('%',#{query},'%') or c.cname like concat('%',#{query},'%')) </if> "
            + " </where> "
            + " </script> ")
    List<Component> selectByIdOrName(@Param("query") String query);
}
